import java.util.Scanner;

public class WaterBottles {
    /*
    题目描述
    小区便利店正在促销，用 numExchange 个空酒瓶可以兑换一瓶新酒。你购入了 numBottles 瓶酒。
    如果喝掉了酒瓶中的酒，那么酒瓶就会变成空的。
    请你计算 最多 能喝到多少瓶酒。
    链接：https://leetcode-cn.com/problems/water-bottles
     */
    public static int numWaterBottles(int numBottles, int numExchange) {
        int sum = 0; //最终喝到的酒的总数
        int empty_bottles = numBottles; //空瓶的数量
        while (numBottles !=0){
            sum += numBottles;
            numBottles = empty_bottles/numExchange;
            empty_bottles  = empty_bottles%numExchange+numBottles;
        }
        return  sum;

    }


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int numBottles = scanner.nextInt();


        int numExchange = scanner.nextInt();
        System.out.printf("初始购入%d瓶酒,%d个空酒瓶可以换一瓶新酒\n",numBottles,numExchange);
        System.out.printf("最终喝了%d瓶酒",numWaterBottles(numBottles,numExchange));

    }
}
